home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / tlx_sq21.zip / RING.SLT < prev    next >
Text File  |  1992-03-20  |  18KB  |  574 lines

  1. // RING.SL? Do the actual calling. Returns no. of BBSes left to call,
  2. //                                 or -1 if fail.
  3. //
  4. // This script is called by the QDIAL script.
  5.  
  6. // Please look at the comments through the whole file, and modify to
  7. // suit your needs, BEFORE you use it. Then recompile with CS RING.
  8. //-----------------------------------------------------------
  9.  
  10. // If you have suggestions for improving this script, please suggest
  11. // improvements to me via old-fashioned snail-mail to:
  12.  
  13. // Author:  Inge Vabekk
  14. //          Hamangskogen 108
  15. //          N-1300 SANDVIKA
  16. //          NORWAY
  17. //          tel. (472) 546 396
  18.  
  19. str bbs_name[80]               // Name of current BBS (from operator)
  20.    ,help    [80]               // Temporary help string.
  21.    ,display  []="DISPLAY"
  22.    ,change   []="CHANGE"       // Must be set to update display.
  23.    ,global   []="GLOBAL"
  24.    ,logon  [14]="LOGON"        // Logon script
  25.    ,getname  []="GETNAME"      // Script to read NAME.DAT file.
  26.    ,bbsname  []="BNAME"        // Global containing BBS name.
  27.    ,short    []="SHORT"        // Global containing "short" name.
  28.    ,cprot    []="CPROT"        // Global defining current protocol.
  29.    ,lastk    []="LASTK"        // Last key pressed.
  30.    ,prompt   []="PROMPT"       // Global command prompt.
  31.    ,command  []="Command"      // Default command prompt.
  32.    ,read[]="R"
  33.    ,write[]="W"
  34.    ,DialPrfx[]="DIAL"          // Dialfile prefix     
  35.    ,DialSufx[]=".STR"          // Dialfile suffix
  36.    ,DialString[14]="DIAL.STR"  // Dial string file
  37.    ,NextString[14]=""          // Next dial string
  38.    ,NumberStr  [4]             // Number string
  39.    ,DialList  [60]=""          // List of dial strings.
  40.    ,BBS [32] = "FAIL" 
  41.    ,uldir    [64]              // Upload mail directory.
  42.    ,dlfile   [12]              // Download command filename.
  43.    ,ulfile   [12]              // Upload filename.
  44.    ,check     [4]              // Temporary.
  45.    ,kepre     [4]              // Temporary.
  46.    ;
  47.  
  48. int tmark          // Used for timing.
  49.    ,MaxNumber      // Max. number of BBSes to dial.
  50.    ,LastNumber     // Previously dialled number
  51.    ,BBSnumber      // Dial string number.
  52.    ,oldBBSnumber   // Previous number
  53.    ,voice          // = 1 (TRUE) for voice calls
  54.    ,f              // File handle.
  55.    ,busy, OK, nocarrier, notone  // For tracking.
  56.    ,stat, calling
  57.    ,uls,dls        // Uploads, Downloads.
  58.    ;
  59.  
  60. //-----------------------------------------------------------
  61. // Script starts here.
  62. //-----------------------------------------------------------
  63.  
  64. main(int line)
  65. {
  66. int c, i, j, ll, repeat, ring;
  67.  
  68.   ring = 0;
  69.   chkring(ring);                         // Start tracking phone ring.
  70.   _scr_chk_key = 1;
  71.   call (global,read,bbsname,bbs_name);   // Get the name of the BBS.
  72.  
  73.   gotoxy (0,line);
  74.  
  75. // Check the name. If not "CONT", delete old dial strings.
  76.  
  77.   NextString="DIAL*.STR";
  78.   BBSnumber=0;
  79.   if (strcmpi(bbs_name,"cont")==0)
  80.   { setchrs(DialList,0,0,60);          // Clear dial list.
  81.     while (filefind(NextString,0,DialString)) 
  82.     { NextString = "";                 // For each string found:
  83.       for (i=0; i<4; ++i) setchr(DialString,i,' ');
  84.       i = stoi (DialString);
  85.       itos (i,NumberStr);
  86.       if (i>BBSnumber) BBSnumber = i;
  87.       i = i*2-2;                       // Define place in string.
  88.       setchr(DialList,i,subchr(NumberStr,0));
  89.       setchr(DialList,i+1,subchr(NumberStr,1));
  90.     }
  91.     MaxNumber = BBSnumber*2-2;         // Set highest number.
  92.   }
  93.   else
  94.   { while (filefind(NextString,0,DialString))  fdelete (DialString);
  95.     if (subchr(bbs_name,0)!='@')
  96.       find_number ();
  97.     else
  98.     { subchrs (bbs_name,1,79,bbs_name);// Filename: Remove 1.st char.
  99.       if (!f) fclose(f);
  100.       f = fopen(bbs_name,"r");
  101.       if (f <= 0)
  102.       { printsc ("T²: ");
  103.         printsc (bbs_name);
  104.         prints (" not found!");
  105.       }
  106.       while (fgets(bbs_name,80,f) > 0) // Read a line.
  107.         find_number ();
  108.       fclose(f);                       // Close the file again.
  109.       f = 0;
  110.     }
  111.   }
  112.   blue();
  113.  
  114.   if (BBSnumber<1)
  115.   { prints ("T²: No BBSes found to call (check modem speed settings!)");
  116.     return (0);                        // No BBSes found.    
  117.   }
  118.  
  119. // Dial the round of files.
  120. //-----------------------------------------------------------
  121.  
  122.   oldBBSnumber = -99;
  123.   LastNumber = MaxNumber+2;
  124.   while (BBSnumber>0)                  // Until list is exhausted.
  125.   { for (i=0; i<2; ++i)
  126.     { do
  127.       { LastNumber=LastNumber+2;
  128.         if (LastNumber>MaxNumber) LastNumber=0;
  129.         subchrs (DialList,LastNumber,2,check);
  130.         if (check !="") goto proceed;
  131.       } while (LastNumber < MaxNumber);
  132.     }
  133.     return (0);                        // No more dial files.
  134.     
  135. //  Go ahead, dial.
  136.  
  137. Proceed:
  138.     DialString = DialPrfx;
  139.     strcat(DialString,check);
  140.     strcat(DialString,DialSufx);       // Build dial string name.
  141.     cputs_tr(_mdm_init_str);
  142.     waitfor ("OK",1);
  143.     clear_scr();
  144.  
  145.     if (!f) fclose(f);
  146.     f = fopen(DialString,"r");
  147.     if (f<=0)
  148.     { printsc ("T²: FILE OPEN ERROR on file ");
  149.       printsc (DialString);
  150.       prints ("!");
  151.       prints ("I could not open the above file. The reason for this may be");
  152.       prints ("that there are too few file handles, or that several files");
  153.       prints ("have not been properly closed (script aborted?).");
  154.       prints ("");
  155.       prints ("Please exit from Telix and try again. If the error");
  156.       prints ("persists, please call the author:");
  157.       prints ("     Inge Vabekk");
  158.       prints ("     Hamangskogen 108");
  159.       prints ("     N-1300 SANDVIKA");
  160.       prints ("     NORWAY");
  161.       prints ("");
  162.       printsc ("at the ");
  163.       printc ('"');
  164.       printsc ("Non Plus Ultra MBBS");
  165.       printc ('"');
  166.       prints (", tel (472) 46 51 27 or 46 39 56!");
  167.       setchr (DialList,LastNumber,0);  // Error!
  168.       return (-1);
  169.     }
  170.     fgets (help,64,f);                 // Check if we have the
  171.     bbs_name = "Calling ";
  172.     strcat (bbs_name,help);
  173.     strcat (bbs_name,".");
  174.  
  175.     j=0;
  176.     for (i=0; i<25; ++i)               // download file.
  177.     { c = toupper(subchr(help,i));
  178.       if (c == 0) break;
  179.       if (c >= 'A')
  180.       { if (isalpha(c))
  181.         { setchr (dlfile,j,c);
  182.           if (++j>7) break;            // Max. 8 characters (0-7).
  183.         }
  184.       }
  185.     }
  186.     setchr (dlfile,j,0);               // Name of download file.
  187.     call (global,write,short,dlfile);  // Set name into global.
  188.  
  189.     j = 0;
  190.     if (!getenv ("XBOARD",uldir)       // Check for XBoard.
  191.     && (j=fopen("XBOARD.DIR","r")) < 1)// If not
  192.     { uldir=_up_dir;                   // defined, build name of
  193.       strcat (uldir,dlfile);           // directory for upload files,
  194.       exec ("CRDIR",uldir);            // and try to create it.
  195.     }
  196.     if (j)                             // XBoard definition on file:     
  197.     { fgets (uldir,64,j);              // Read dir.name.
  198.       fclose (j);
  199.     }
  200.  
  201.     blue();
  202.     chkring(ring);
  203.  
  204.     _scr_chk_key = 0;
  205.  
  206.     for (ll=strlen(help); ll>0; --ll)
  207.     { if (subchr(help,ll) > ' ') break;
  208.       setchr (help,ll,0);
  209.     }
  210.     box (17,8,51,14,2,0,36);
  211.     ll = 17 + (51-17 -ll)/2;           // Center this line (name).
  212.     
  213.     pstraxy ("Press 'ESC' to abort dialing.",20,10,36);
  214.     pstraxy ("Press 'D' to stop dialing",    22,11,36);
  215.     pstraxy (help,                           ll,12,36);
  216.     gotoxy (0,line);
  217.     keyset (27, 0,"@Escape");          // Enable ESCAPE key.
  218.     keyset ('d',0,"@DCHAR");           // Enable "D" key.
  219.     keyset ('D',0,"@DCHAR");
  220.  
  221.     fgets (help,3,f);                  // Read number of entries.
  222.     repeat = stoi (help);              // Get repeat number.
  223.     fgets (help,80,f);                 // Find protocol.
  224.     check = help;                      // Set protocol
  225.     setchr (check,1,0);                // into global.
  226.     call (global,write,cprot,check);   
  227.  
  228.     fgets (logon,14,f);                // Find logon script.
  229.     voice = strposi(logon,"VOICE",0)>=0; // Voice?
  230.     fgets (help,80,